﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core;
using Telerik.Windows.Controls;
using Baosight.ZNH.ZMCM.UI.ChildWindows;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Telerik.Windows.Controls.GridView;
using Baosight.Platform.Core.ServiceModel;

namespace Baosight.ZNH.ZMCM.UI
{
    public partial class ZMCM92 : EFViewCmes
    {
        private string fdMaterialId = "";
        public ZMCM92()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 查看
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            HyperlinkButton link = sender as HyperlinkButton;
            EIRow row = (link.ParentOfType<GridViewRow>().Item as UIBaseEntity).GetEIRow();
            fdMaterialId = row["fdMaterialId"].ToString();
            EIInfo eiInfo = new EIInfo();
            eiInfo.Set("service", "ZMCM92");
            eiInfo.Set("method", "queryImNExportDetail");
            eiInfo.Set("fdMaterialId", fdMaterialId);
            eiInfo.Set("fdHisKeyId", this.fdHisKeyId.Value);
            eiInfo.Set("fdYear", this.fdYear.Value);
            eiInfo.Set("fdMonth", this.fdMonth.Value);
            EIBlock eIBlock = new EIBlock("result");
            eIBlock.SetRow(0, row == null ? new EIRow() : row);
            eiInfo.AddBlock(eIBlock);

            base.Submit(eiInfo, DoOperationCompleted);
        }

        public void DoOperationCompleted(object sender, DoWorkCompletedEventArgs e)
        {
            EIInfo inInfo = e.EIInfo;
            if (inInfo.Status == -1)
            {
                string _msg = inInfo.GetMsg();
                this.OpenEFWindowAlert(_msg, true);//列表中删除，操作失败后按钮生效
                return;
            }

            OpenDetailPopup(e.EIInfo, "物资出入库明细-查看", "detail", null);
        }

        /// <summary>
        /// 新增或修改之前的数据传输
        /// 构造新增页面内容、弹出页面
        /// </summary>
        /// <param name="eIInfo"></param>
        /// <param name="title"></param>
        public void OpenDetailPopup(EIInfo _eIInfo, string _title, string _dialogType, string _args)
        {
            BaseDetail view = new BaseDetail();//构造一个新的修改页面
            view.EIDataContext = new Platform.Core.UI.EIDataContext();
            view.EIDataContext.Update(_eIInfo);

            view.fdMaterialId.Value = fdMaterialId;
            view.fdHisKeyId.Value = this.fdHisKeyId.Value;
            view.fdYear.Value = this.fdYear.Value;
            view.fdMonth.Value = this.fdMonth.Value;

            CmesWindows _popup = new CmesWindows();//构造一个弹出页面  
            _popup.ResizeMode = ResizeMode.NoResize;//设置不能修改窗口大小
            _popup.Header = _title == null ? "" : _title;//设置Title
            _popup.Content = view;//让新增页面在弹出窗口显示
            _popup.Closed += new EventHandler<WindowClosedEventArgs>(DetailWindow_Closed);
            _popup.ShowDialog();//模态显示弹出窗口
        }

        /// <summary>
        /// 弹出窗口关闭时执行的方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DetailWindow_Closed(object sender, WindowClosedEventArgs e)
        {
            //超链接生效
            if (base.TempHyperlink != null)
            {
                base.TempHyperlink.IsEnabled = true;
                base.TempHyperlink = null;
            }
        }
    }
}
